﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Diagnostics;
using System.Reflection;

namespace IRC.IRepairClouds.DataLayer.Expressions
{
    partial class Extensions
    {
        public static ExpressionBuilder<TRes> Member<T, TRes>(this ExpressionBuilder<T> expression, Expression<Func<T, TRes>> selector)
        {
            ParametersReplacer pr = new ParametersReplacer(selector.Body, expression);
            var exp = pr.Process();
            switch (exp.NodeType) {
                case ExpressionType.MemberAccess:
                    return ((MemberExpression)exp);//.ToExpressionBuilder<TRes>();
                case ExpressionType.Call:
                    return ((MethodCallExpression)exp);//.ToExpressionBuilder<TRes>();
            }
            return null;
        }
    }
}
